package com.founder.gateway.controller;

import com.founder.gateway.orm.fzapi.bean.entity.ApiSchemeEntity;
import com.founder.gateway.orm.fzapi.bean.entity.UserEntity;
import com.founder.gateway.service.impl.ApiServiceImpl;
import com.founder.gateway.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/******************************************************************************
 * @Package: [com.founder.gateway.controller.MyController]
 * @ClassName: [MyController]
 * @Description: [一句话描述该类的功能]
 * @Author: [fengli@founder.com.cn]  
 * @CreateDate: [2019/1/11 10:21]   
 * @UpdateUser: [fengli@founder.com.cn (如多次修改保留历史记录，增加修改记录)]   
 * @UpdateDate: [2019/1/11 10:21，(如多次修改保留历史记录，增加修改记录)]   
 * @UpdateRemark: [说明本次修改内容, (如多次修改保留历史记录 ， 增加修改记录)]
 * @Version: [v1.0]
 * ${tags}
 */
@RestController
public class MyController {
    @Autowired
    private ApiServiceImpl apiService;
    @Autowired
    private UserServiceImpl userService;
    /**
     * 本方法用于显示api_scheme表中的内容
     * @return
     */
    @RequestMapping("/showScheme")
    @ResponseBody
    public Map<String,ApiSchemeEntity> showScheme(){
        Map<String,ApiSchemeEntity> result=new HashMap<>();
        HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
        response.setHeader("Access-Control-Allow-Origin", "*");
        ApiSchemeEntity apiSchemeEntity= apiService.queryApiScheme("0232ba6275f542c686cb70ddd0489cdc");
        result.put("result", apiSchemeEntity);
        return result;
    }

    @RequestMapping("/getUser")
    @ResponseBody
    public Map<String, UserEntity> getUser(){
        Map<String,ApiSchemeEntity> result=new HashMap<>();
        UserEntity userEntity;
        return  null;
    }

    @RequestMapping("/sigin")
    @ResponseBody
    public Map<String, UserEntity> siginUser(){
        Map<String,ApiSchemeEntity> result=new HashMap<>();
        UserEntity userEntity;
        userService.createUsr("fengli", "123");
        return  null;
    }

    @ResponseBody
    @RequestMapping("/delete")
    public Map<String, UserEntity> delete(){
        Map<String,ApiSchemeEntity> result=new HashMap<>();
        UserEntity userEntity;
        userService.createUsr("fengli", "123");
        return  null;
    }
}
